package com.study;


import com.study.cglib.LogServiceCglib;
import com.study.proxy.LogServiceProxy;
import com.study.service.IUserService;
import com.study.service.UserServiceImpl;
import net.sf.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

public class demo1 {

    public static void main(String[] args) {

        IUserService userService = new UserServiceImpl();
        LogServiceProxy logServiceProxy = new LogServiceProxy(userService);
        IUserService userServiceProxy = (IUserService) Proxy.newProxyInstance(userService.getClass().getClassLoader(), userService.getClass().getInterfaces(), logServiceProxy);
        userServiceProxy.addUser("杨通通");


        LogServiceCglib logServiceCglib = new LogServiceCglib(userService);
        IUserService iUserService = (IUserService)Enhancer.create(userService.getClass(), logServiceCglib);
        iUserService.deleteUser("ytt");

    }
}
